import { createStore } from "redux";
import { combineReducers } from "redux";

function A(state = 0, action) {
    switch (action.type) {
        case "add":
            return state + 1;
        default:
            return state;
    }
}

function B(state = {name:"jack"}, action) {
    switch (action.type) {
        case "jian":
            return {name:'jian'}
        default:
            return state;
    }
}

const reducers = combineReducers({A,B});  //A和B两个reducer各自维护自己的状态，把返回的状态放到自己的键中。
const store = createStore(reducers);
store.dispatch({type:"add"});
console.log(store.getState());  //{A:1,B:"jack"}
store.dispatch({type:"jian"});
console.log(store.getState());  //{A:1,B:"jian"}

